/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 22652
 * Date: 2024-04-07
 * Time: 22:41
 */
public class test_2 {
    private static Object loket1 =new Object();
    private static Object loket2 =new Object();
    private static Object loket3 =new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(()->{
                    System.out.println(Thread.currentThread().getName());
                    synchronized (loket2){
                        loket2.notify();
                    }
        },"C");
        Thread thread2 = new Thread(()->{
            try {
                synchronized (loket2) {
                    loket2.wait();
                }
                System.out.println(Thread.currentThread().getName());
                synchronized (loket3){
                    loket3.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"B");
        Thread thread3 = new Thread(()->{
            try {
                synchronized (loket3) {
                    loket3.wait();
                }
                System.out.println(Thread.currentThread().getName());
                synchronized (loket1){
                    loket1.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"A");
        thread1.start();
        thread2.start();
        thread3.start();
        //Thread.sleep(1000)

        System.out.println("结束了");
    }
}
